<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>广东省传播平台-刊例资源列表</title>
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/common.css" />
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/tag.css" />
		<script type="text/javascript" src="<%=path%>/js/jquery-1.7.2.js"></script>
		<link type="text/css"
			href="<%=path%>/js/jquery-ui-1.8.21.custom/css/smoothness/jquery-ui-1.8.21.custom.css"
			rel="stylesheet" />
		<script type="text/javascript"
			src="<%=path%>/js/jquery-ui-1.8.21.custom/js/jquery-ui-1.8.21.custom.min.js"></script>
		<script type="text/javascript">
	function pageSub(currentPage) {
		 var reg=/^\d*?$/;
		 var total =${page.totalPages};
		 if(reg.test(currentPage)){
		 	if(currentPage > total){
		 		$("#currentPage").val(total);
		 	}else{
		 		$("#currentPage").val(currentPage);
		 	}
		 	find();
			document.forms[0].action="mediaPriceAction.action";
			document.forms[0].submit();
		}else{
			  alert("请输入数字!"); 
		}
	}
	
	//重置
	function rewlset(){
		var myDate = new Date(); 
		var year = myDate.getFullYear().toString(10).substring(0,4);//当年
		//alert(year);
		$("#city").val($("#usercity").val());//城市
		$("#mediaDiscountType").val("");//媒体类型
		$("#mediaType").val("");//媒体类型
		$("#years").val(year);//当前
		$("#mediaName").val("输入媒体名称");
	}
	
	//提交
	function doSubmit(url){
		document.forms[0].action=url;
		document.forms[0].submit();
	}
	
	function changeKeyword(){
		$("#mediaName").val("");
	}
	
	function delMedia(priceID,mediaID){
		if(confirm('确定删除该条记录？')){
			$.ajax({
		        url: "delMediaByIdAction.action?"+new Date()+"&priceID="+priceID+"&mediaID="+mediaID,
		        type:"POST",
		        cache:false,
		        success: function(message)
		        {
			    	if(message == "success")
			    	{
		        		alert("该条记录删除成功！");
		        		//ajaxLoad('main_right','getLablesListByPage.action?tagType=all');
		        		window.location.href="mediaPriceAction.action";
		        	}
		        	if(message == "error"){
			    		alert("刊例正在使用，删除失败 ！");
		        	}
		   		}
	     	});
		}
	}
	
	function doSelectByMediaName(url){
		if(find()){
			document.forms[0].action=url;
			document.forms[0].submit();
		}
	}
	
	function find(){
		var mediaName = $('#mediaName').val();
		//去除空格
		$('#mediaName').val(trim(mediaName));
		if($('#mediaName').val(trim(mediaName))=="输入媒体名称"){
			$("#mediaName").val("");
		}
		if(trim(mediaName)==''){
		$("#mediaName").val('');}
		if(null !=mediaName){
			if(mediaName.indexOf("%")>-1){
				alert("查询条件不能包含'%'符号！");
				return false;
			}
			if(mediaName.indexOf("@")>-1){
				alert("查询条件不能包含'@'符号！");
				return false;
			}
			if(mediaName.indexOf("<")>-1){
				alert("查询条件不能包含'<'符号！");
				return false;
			}
			if(mediaName.indexOf(">")>-1){
				alert("查询条件不能包含'>'符号！");
				return false;
			}
			if(mediaName.indexOf("&")>-1){
				alert("查询条件不能包含'&'符号！");
				return false;
			}
		}
		return true;
	}
	function trim(str) 
		{
		str = str.replace( /^\s*/, "");
		str = str.replace( /\s*$/, "");
		str = str.replace( /^[" "|"　"]*/, "");
		str = str.replace( /[" "|"　"]*$/, ""); 
		return str;
	} 
	
    //合同详情
    function contractDetail(contractID){
	var url = encodeURI(encodeURI("turnToContractDetail.action?contractID=" +contractID+"&toType=2"));
	window.location.href=url;
    }
</script>

<script type="text/javascript">
		//获取文件扩展名   
		function getFileExtendName(filePath){  
		   var extendName = '';  
		 if(filePath != null && $.trim(filePath).length > 0){  
		       filePath = $.trim(filePath);  
		       extendName = filePath.substring(filePath.lastIndexOf(".") + 1, filePath.length);  
		    }  
		    return extendName;  
		}  
		  
		//验证文件扩展名   
		function checkFileExtendName(filePath){  
		    var extendName = getFileExtendName(filePath);  
		   //根据需求定制   
		   var accept_extend = new Array("xls","xlsx");  
		 	var flag = false;  
		 	if(extendName != ''){  
		      for(var i=0; i<accept_extend.length; i++){  
		          if(extendName.toLowerCase() == accept_extend[i])  
		              flag = true;  
		       }  
		   }  
		   return flag;  
		} 
	function checkFileType(){
		if($.trim($("#uploadFile").val()) ==""){
			alert('请选择上传附件！');
		    return false;
		}else  if(!checkFileExtendName($("#uploadFile").val())){
			alert('文件格式错误,请上传xlsx或xls格式的文件！');
		     return false;
		}else{
			$("#dialog_Upload").parent().appendTo("#form1");
			return true;
		}
	}
</script>

<script type="text/javascript">
	$(function(){
		$('#dialog_01').dialog({
			autoOpen: false,
			width: 500,
			height: 510,
			show: "blind",
			hide:"slide"
			//position: [800,220]  //显示位置
			//modal: true, overlay: { opacity: 0.5, background: "black" } ,	
		});
		$('#dialog_01_btn').click(function(){
			$('#dialog_01').dialog('open');
			return false;
		})
	
		$('#dialog_Upload').dialog({
			autoOpen: false,
			width: 300,
			height: 160,
			resizable: false,
			show: "slide",
			hide:"blind",
			//position: [800,220]  //显示位置
			//modal: true, overlay: { opacity: 0.5, background: "black" } ,	
			buttons: {
				"导入": function() {
					if($.trim($("#uploadFile").val()) ==""){
						alert('请选择上传附件！');
						document.getElementById('uploadFile').focus();
					    return false;
					}else  if(!checkFileExtendName($("#uploadFile").val())){
						alert('文件格式错误,请上传xlsx或xls格式的文件！');
					     document.getElementById('uploadFile').focus();
					    return false;
					}
					$("#dialog_Upload").parent().appendTo("#form1");
					document.getElementById("dialog_Upload_btn").disabled = true;
					doSubmit('doAddMediaByExcelAction.action');
					$(this).dialog("close");
				},
				"取消": function() {
					$(this).dialog("close");
				}
			}
		});
		$('#dialog_Upload_btn').click(function(){
			$('#dialog_Upload').dialog('open');
			return false;
		})
		
		$('#tempDiv').empty();
		//if($.trim($("#uploadErrorMessageHidden").val())!=""){
		//	$("#uploadErrorMessageAlert").html("导入成功，请查看错误信息！");
		//}else{
		//	$("#uploadErrorMessageAlert").html("");
		//}
		
		var msg ='${uploadErrorMessage}';
		var noError = '${noError}';
		if(null !=msg && msg !=''){
			alert("导入成功，请查看错误信息！");
			$("#dialog_01_btn_spanId").show();
		}else if(null!=noError && noError!=''){
			alert("导入成功！");
		}
	});
</script>

	</head>

	<body>
		<script type="text/javascript">
	$(function(){
        //selectNav('nav2');
    });
</script>
		<!-- 顶栏start -->
		<jsp:include page="../common/top.jsp"></jsp:include>
		<!-- 顶部end -->

		<!-- 顶部start -->
		<div id="main">
			<div class="body">
				<jsp:include page="../common/nav.jsp"></jsp:include>
				<!-- 主体 -->
				<div class="main_body">
					<form action="" id="form1" method="post" enctype="multipart/form-data">
						<table class="condition bg1"
							style="width: 100%; font-size: 14px; font-weight: bold; color: #000000;"
							align="center">
							<tr>
								<td width="8%" style="height: 40px; text-align: right;">
									<label>
										年份：
									</label>
								</td>
								<td width="15%" style="height: 40px;">
									<s:select id="years" name="years" list="yearsList"
										listKey="contractYear" listValue="contractYear"></s:select>
								</td>
								<td width="15%" style="height: 40px;">
									<s:select id="mediaType" name="mediaType" list="mediaTypeList"
										listKey="id" listValue="datavalue" headerKey=""
										headerValue="--(全)媒体类型--">
									</s:select>
								</td>
								<td width="15%" style="height: 40px;">
									<s:select id="city" name="city" list="citylist" listKey="id"
										listValue="datavalue">
									</s:select>
									<input type="hidden" id="usercity" value="${logUser.usercity}"/>
								</td>
								
								<td width="30%" style="height: 40px;text-align: center;">
									&nbsp;&nbsp;&nbsp;<span style="color:red;" id="uploadErrorMessageAlert"></span>
								</td>
							</tr>
							<tr>
								<td style="height: 40px; width: 8%; text-align: right;">
									<label>
										折扣类型：
									</label>
								</td>
								<td style="height: 40px; width: 15%;">
									<s:select id="mediaDiscountType" name="mediaDiscountType"
										list="mediaDiscountTypeList" listKey="id"
										listValue="datavalue" headerKey="" headerValue="--折扣类型--">
									</s:select>
								</td>
								<td style="height: 40px; width: 15%;">
									<input type="text" id="mediaName" name="mediaName" class="text"
										value="${mediaName}" onfocus="changeKeyword();" />
								</td>
								<td style="height: 40px; text-align: left;" colspan="2">
									<input type="button" class="btn-title" value="搜索"
										onclick="doSelectByMediaName('mediaPriceAction.action');" />
									&nbsp;&nbsp;&nbsp;
									<input type="button" class="btn-title" value="重置"
										onclick="rewlset();" />
								</td>
								<td style="height: 40px; text-align: right;" valign="middle">
							 <input type="button" value="媒体刊例导入" class="btn-title" onclick="doSubmit('toUploadMeduaAction.action');"/>
							 <span id="dialog_01_btn_spanId" style="display:none;">&nbsp;&nbsp;
							  <input type="button" id="dialog_01_btn" class="btn-title" value="错误信息"/></span>
							
							  <!-- 
							  <input type="hidden" id="uploadErrorMessageHidden" value="${uploadErrorMessage}"/>
							   -->
							  &nbsp;&nbsp;
									<input type="button" class="btn-title" value="新增"
										onclick="doSubmit('toAddMediaPriceAction.action');" />
									&nbsp;&nbsp;&nbsp;
								</td>
							</tr>
						</table>

						<div id="list_div">
							<input type="hidden" name="currentPage" id="currentPage" />
							<table class="table_list" width="100%">
								<tr class="bg">
									<th>
										媒体名称
									</th>
									<th>
										媒体类型
									</th>
									<th>
										媒体归属
									</th>
									<th>
										供应商
									</th>
									<th>
										代理商
									</th>
									<th>
										归属地市
									</th>
									<th>
										折扣类型
									</th>
									<th>
										年份
									</th>
									<th>
										操作
									</th>
								</tr>
								<s:iterator value="mpList" id="mp">
									<tr>
										<td>
											<a href="#" class="underline" style="cursor:hand;" title="${mp.mediasumm.mediaName}" onclick="doSubmit('mediumDetailAction.action?priceID=${mp.priceID}');">
											<s:if test="#mp.mediasumm.mediaName.length()>10">
												<label title="${mp.mediasumm.mediaName}">
													<s:property
														value="#mp.mediasumm.mediaName.substring(0,10)+'...'" />
												</label>
											</s:if>
											<s:else>
												<s:property value="#mp.mediasumm.mediaName" />
											</s:else>
											</a>
										</td>
										<td>
											<s:iterator id="mtl" value="mediaTypeList">
												<s:if test="#mtl.id == #mp.mediasumm.mediaType">
													<s:if test="#mtl.datavalue.length()>10">
														<label title="${mtl.datavalue}">
															<s:property value="#mtl.datavalue.substring(0,10)+'...'" />
														</label>
													</s:if>
													<s:else>
														<s:property value="#mtl.datavalue" />
													</s:else>
												</s:if>
											</s:iterator>
										</td>
										<td>
											<s:iterator value="mediaBelogList" id="md">
												<s:if test="#md.id == #mp.mediaBelog">
													<s:if test="#md.datavalue.length()>10">
														<label title="${md.datavalue}">
															<s:property value="#md.datavalue.substring(0,10)+'...'" />
														</label>
													</s:if>
													<s:else>
														<s:property value="#md.datavalue" />
													</s:else>
												</s:if>
											</s:iterator>
										</td>
										<td>
											<s:if test="#mp.mediasumm.mediaProvider.length()>10">
												<label title="${mp.mediasumm.mediaProvider}">
													<s:property
														value="#mp.mediasumm.mediaProvider.substring(0,10)+'...'" />
												</label>
											</s:if>
											<s:else>
												<s:if
													test="#mp.mediasumm.mediaProvider == null || #mp.mediasumm.mediaProvider==''">
													无
												</s:if>
												<s:else>
													<s:property value="#mp.mediasumm.mediaProvider" />
												</s:else>
											</s:else>
										</td>
										<td>
											<s:if test="#mp.mediaAgent.length()>10">
												<label title="${mp.mediaAgent}">
													<s:property value="#mp.mediaAgent.substring(0,10)+'...'" />
												</label>
											</s:if>
											<s:else>
												<s:if test="#mp.mediaAgent == null || #mp.mediaAgent==''">
													无
												</s:if>
												<s:else>
													<s:property value="#mp.mediaAgent" />
												</s:else>
											</s:else>
										</td>
										<td>
											<s:iterator value="citylist" id="cl">
												<s:if test="#cl.id == #mp.city">
													<s:if test="#cl.datavalue.length()>10">
														<label title="${cl.datavalue}">
															<s:property value="#cl.datavalue.substring(0,10)+'...'" />
														</label>
													</s:if>
													<s:else>
														<s:property value="#cl.datavalue" />
													</s:else>
												</s:if>
											</s:iterator>
										</td>
										<td>
											<s:iterator value="mediaDiscountTypeList" id="mdt">
												<s:if test="#mdt.id == #mp.mediaDiscountType">
													<s:if test="#mdt.datavalue.length()>10">
														<label title="${mdt.datavalue}">
															<s:property value="#mdt.datavalue.substring(0,10)+'...'" />
														</label>
													</s:if>
													<s:else>
														<s:property value="#mdt.datavalue" />
													</s:else>
												</s:if>
											</s:iterator>
										</td>
										<td>
											${mp.contractYear}
										</td>
										<td>
											<c:if test="${logUser.usercity eq mp.city}">
											<a href="#" title="编辑"
												onclick="doSubmit('toUpdateMediaAction.action?priceID=${mp.priceID}');">
												<img src="<%=path%>/images/modify.gif" alt="编辑"
													align="absmiddle" /> </a>
													</c:if>
											<a href="#" title="详情"
												onclick="doSubmit('mediumDetailAction.action?priceID=${mp.priceID}');">
												<img src="<%=path%>/images/detail.gif" alt="详情"
													align="absmiddle" /> </a>
											<a href="#" title="刊例"
												onclick="doSubmit('mediumAction.action?priceID=${mp.priceID}&mediaID=${mp.mediaID}&mediaType1=${mp.mediasumm.mediaType}&contractYear=${mp.contractYear}');">
												<img src="<%=path%>/images/toMeiJie.gif" alt="刊例"
													align="absmiddle" /> </a>
											<c:if test="${logUser.usercity eq mp.city}">
											<a href="#"
												onclick="delMedia(${mp.priceID},${mp.mediaID});"
												title="删除"> <img src="<%=path%>/images/delete.gif"
													alt="删除" align="absmiddle" /> </a>
													</c:if>
										</td>
									</tr>
								</s:iterator>
							</table>
							<!-- 分页 -->
							<jsp:include page="/jsp/common/page.jsp"></jsp:include>

						</div>
						
						<div id="dialog_01" title="导入后的错误信息" style="display: none;">
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td style="color:red;">
									${uploadErrorMessage}
								</td>
							</tr>
						</table>
					</div>
					
					<div id="dialog_Upload" title="媒体刊例导入" style="display: none;">
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td style="color:red;padding-top: 20px;padding-left: 15px;">
									<input type="file" id="uploadFile" name="inputfile"/>&nbsp;<span style="color:red">*</span>
								</td>
							</tr>
						</table>
					</div>
					</form>
				</div>
			</div>
		</div>
		<!-- 顶部end -->


		<!-- 底部start -->
		<div id="bottom">
			<div class="body">
				<label>
					版权所有&nbsp;&nbsp;&nbsp;&nbsp;2012东莞移动
				</label>
			</div>
		</div>
		<!-- 底部end -->
	</body>
</html>